package cn.com.cetccst.hostsdk.internal;

import android.content.Context;

import androidx.annotation.NonNull;

import java.util.HashMap;
import java.util.Map;

import cn.com.cetccst.hostsdk.R;
import cn.com.cetccst.sdk.modelbase.BaseResp;
import cn.com.cetccst.sdk.modelbase.ErrorMessage;


public class SDKErrorCode implements BaseResp.ErrCode {

    public static final int
            ERROR_OK = ERR_OK,
    //接入sdk采用2打头的错误码
    ERROR_NOT_SET_LOCAL_HANDLER = 2_01_001;

    private static Map<Integer, String> errorMessages;

    public static void initialize(@NonNull final Context context) {
        if (errorMessages == null)
            errorMessages = new HashMap<>() {
                {
                    putAll(ErrorMessage.getMap());
                    put(ERROR_NOT_SET_LOCAL_HANDLER, context.getString(R.string.ss_hostsdk_not_set_local_handler));
                }
            };
    }

    public static String getErrorMessage(int errorCode) {
        return errorMessages.get(errorCode);
    }

    public static void setDefaultErrorInfo(BaseResp baseResp, int code) {
        baseResp.errorCode = code;
        if (code == ERROR_OK) {
            baseResp.errorStr = null;
        } else {
            baseResp.errorStr = getErrorMessage(code);
        }
    }
}
